package com.bridge.common.intercepters;

import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.List;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * author : bridge.24
 * date   : 21.1.815:35
 * desc   :  动态添加后缀名字
 */
public class AddUrlInterceptor implements Interceptor {
    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        HttpUrl oldUrl = chain.request().url();
        //获取request的创建者builder
        List<String> segments = oldUrl.pathSegments();
        String oldUrlStr = oldUrl.toString();
        HttpUrl newUrl = HttpUrl.parse(oldUrlStr);
        Request.Builder builder = chain.request().newBuilder();
        return chain.proceed(builder.url(newUrl).build());
    }
}
